import bb.cascades 1.2

Page {
    property bool empty: contactManager.contacts.size() == 0
    Container {
        layout: DockLayout {}
        ListView {
            visible: !empty
            property variant layoutFrame
            dataModel: contactManager.contacts
            id: heldenlist
            horizontalAlignment: HorizontalAlignment.Fill
            listItemComponents: [
                ListItemComponent {
                    type: "item"
                    HeldenListitem {
                        id: item
                        title: ListItemData.name.toString()
                        favourite: ListItemData.favourite
                        checkable: false
                        onFavouriteChanged: {
                            ListItem.view.contactFavouriteChanged(ListItemData.phone.toString(), item.favourite);
                        }
                        //description: ListItemData.phone.toString()
                    }
                }
            ]
            attachedObjects: [
                LayoutUpdateHandler {
                    onLayoutFrameChanged: {
                        heldenlist.layoutFrame = layoutFrame;
                    }
                }
            ]
            function contactFavouriteChanged(number, favourite) {
                contactManager.contactFavouriteChanged(number, favourite);
            }
        }
        Container {
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill
            visible: empty
            id: heldenempty
            layout: DockLayout {}
            Label {
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                text: qsTr("There is no Held available")
                textStyle.fontSize: FontSize.Large
            }
        }
    }
    onCreationCompleted: {
        console.log("fertig", contactManager.contacts.size());
    }
    /*attachedObjects: [
        GroupDataModel {
            objectName: "contactsModel"
            id: contactsmodel
            onItemAdded: {
                empty = false;
            }
            onItemRemoved: {
                empty = contactsmodel.size() == 0;
            }
            grouping: ItemGrouping.ByFirstChar
        }
        ]*/
}
